/*
 * @Author: moqian 2898089131@qq.com
 * @Date: 2022-05-05 21:40:38
 * @LastEditors: moqian 2898089131@qq.com
 * @LastEditTime: 2022-05-09 06:44:19
 * @FilePath: /mqtt_ds18b20/inc/database.h
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
/********************************************************************************
 *      Copyright:  (C) 2022 Zhang Changxing<ZhangChangxingVIP@163.com>
 *                  All rights reserved.
 *
 *       Filename:  database.h
 *    Description:  This head file 
 *
 *        Version:  1.0.0(04/13/2022)
 *         Author:  Zhang Changxing <ZhangChangxingVIP@163.com>
 *      ChangeLog:  1, Release initial version on "04/13/2022 01:35:13 AM"
 *                 
 ********************************************************************************/


#ifndef  _DATABASE_H_
#define  _DATABASE_H_

#include "main.h"


/***********************************************************************************************
 *   description:   Database initialization, open the database and create a table
 *          args:   $dbname:    Path and name of the database that you want to open
 *  return value:   <0: failure,    =0:ok 
 ***********************************************************************************************/
int sqlite_init(void);
 

/************************************************************************************************
 *   description:   Insert the data that failed to send into the table of the database
 *          args:   $pack_info:     Packet structure
 *                  $table_name:    Database table name
 *  return value:   <0: failure,    =0:ok 
 ************************************************************************************************/
int db_data_insert(pack_info_t pack_info);


/*************************************************************************************************
 *   description:   Delete the first data in the database
 *          args:   $table_name:    Database table name
 *  return value:   <0: failure,    =0:ok 
 ************************************************************************************************/
int db_data_delete(void);


/**************************************************************************************************************
 *   description:   Find the first data from table_name in the database and store it in the pack_info structure
 *          args:   $pack_info:     Packet structure
 *                  $table_name:    Database table name
 *  return value:   <0: failure,    =0:ok 
 **************************************************************************************************************/
int select_first_data(pack_info_t *pack_info);


/*************************************************************************************************************
 *   description:   Check whether the table is empty
 *          args:   $table_name:    Database table name
 *  return value:   <0: failure,    =0:ok 
 *************************************************************************************************************/
int check_table_data(void);


/***************************************************************************************************************
 *   description:   Determine whether the database is still in use and shut down the database
 *  return value:   <0: failure,    =0:ok 
 ***************************************************************************************************************/
int close_database(void);


#endif   /* ----- #ifndef _DATABASE_H_  ----- */


